# ----------------------------------------------------------------------
#  Paper: Party Competition and Cooperation Shape Affective Polarization
#  Last updated: February 2021
#  Purpose: Prepare INES data (Study I)
#  Outputs: ines_master.csv
#  Machine: Chagai's macbook pro
# ----------------------------------------------------------------------

# ----------------------------------------------------------------------
# load all relevant themes and packages
# ----------------------------------------------------------------------
rm(list=ls())
library("tidyverse")
library("ggplot2")
library("stargazer")
library("xtable")
library("texreg")
library("readstata13")
library("estimatr")
library("naniar")
library("lfe")
library("multiwayvcov")
library("lmtest")

# ----------------------------------------------------------------------
# Clean INES 2019
# ----------------------------------------------------------------------

### Read data
ines_2019 <- read.dta13("Raw Data/INES/2019/Apr-Sep_2019_data_STATA.dta")

### Create treatment -- Time before/after election

# Create election date vector and convert date vector to date format

ines_2019 <- ines_2019 %>% 
  mutate(.,
         election_day = "09/04/2019",
         date = as.Date(date, format = "%d/%m/%Y"),
         election_day = as.Date(election_day, "%d/%m/%Y"))   

# create days before election indicator
ines_2019<- ines_2019 %>% 
  mutate(.,
         days_before_elec = as.numeric(difftime(election_day ,date , units = c("days"))))

# create indicator of self reported partisanship
ines_2019 <- ines_2019 %>% 
  mutate(.,
         right_wing = case_when(
           v111 %in% 1:3 ~ 1,
           v111 %in% 5:7 ~ 0),
         right_wing1 = case_when(
           v111 %in% 1:2 ~ 1,
           v111 %in% 6:7 ~ 0),
         center = ifelse(v111 == 4, 1, 0),
         right = case_when(
           v111 %in% 1:3 ~ 1,
           v111 %in% 4:7 ~ 0),
         left = case_when(
           v111 %in% 1:4 ~ 0,
           v111 %in% 5:7 ~ 1),
         election_year = 2019
  )


# Filter sample to include only Jews
ines_2019 <- ines_2019 %>% 
  filter(.,
         v143_code == 1)


## Create polarization variables
# Left wing parties: Labor (v49C), Meretz (v49F)
# Right wing: Likud (v49A), Jewish Home (v49E), Yamin Hadash (v49D) Israel Betenu (v49H), Otzma (v49S)
# Left wing leaders: Gabbai (v52D)
# Right wing leaders: Bibi (v52A)
# Yemanim: v50
# Smolanim: v51

ines_2019<- ines_2019 %>% 
  replace_with_na(replace = list(v49C = c(98,99),
                                 v49F = c(98,99),
                                 v49A = c(98,99),
                                 v49E = c(98,99),
                                 v49D = c(98,99),
                                 v49H = c(98,99),
                                 v49S = c(98,99),
                                 v52D = c(98,99),
                                 v52G = c(98,99),
                                 v52A = c(98,99),
                                 v52E = c(98,99),
                                 v52F = c(98,99),
                                 v52I = c(98,99),
                                 v50 = c(98,99),
                                 v51 = c(98,99)
  ))

#Recode outcomes and covariates

ines_2019 <- ines_2019 %>% rowwise() %>%  
  mutate(.,
         left_party_affect = mean(c(v49C,v49F), na.rm = T),
         right_party_affect = mean(c(v49A,v49E,v49D,v49H,v49S) , na.rm = T),
         arab_party_affect = mean(c(v49J,v49R), na.rm = T),
         uo_party_affect = v49I,
         ext_right_party_affect = mean(c(v49E,v49D,v49S) , na.rm = T),
         party_affect = case_when(
           right_wing == 1 ~ left_party_affect,
           right_wing == 0 ~ right_party_affect
         ),
         in_party_affect = case_when(
           right_wing == 1 ~ right_party_affect,
           right_wing == 0 ~ left_party_affect
         ),
         party_affect1 = case_when(
           right_wing1 == 1 ~ left_party_affect,
           right_wing1 == 0 ~ right_party_affect
         ),
         party_polar = case_when(
           right_wing == 1 ~ right_party_affect - left_party_affect,
           right_wing == 0 ~ left_party_affect - right_party_affect
         ),
         main_party_polar = case_when(
           right_wing == 1 ~ v49A - v49C,
           right_wing == 0 ~ v49C - v49A
         ),
         extr_party_polar = case_when(
           right_wing == 1 ~ ext_right_party_affect - v49F,
           right_wing == 0 ~ v49F - ext_right_party_affect
         ),
         party_polar1 = case_when(
           right_wing1 == 1 ~ right_party_affect - left_party_affect,
           right_wing1 == 0 ~ left_party_affect - right_party_affect
         ),
         leader_affect = case_when(
           right_wing == 1 ~ v52D,
           right_wing == 0 ~ v52A
         ),
         leader_affect1 = case_when(
           right_wing1 == 1 ~ v52D,
           right_wing1 == 0 ~ v52A
         ),
         leader_polar = case_when(
           right_wing == 1 ~ v52A - v52D,
           right_wing == 0 ~ v52D - v52A
         ),
         leader_polar1 = case_when(
           right_wing1 == 1 ~ v52A - v52D,
           right_wing1 == 0 ~ v52D - v52A),
         left_affect = v51, #towards voters
         right_affect = v50, #towards voters
         affect_voters = case_when(
           right_wing == 1 ~ left_affect,
           right_wing == 0 ~ right_affect
         ),
         affect_voters1 = case_when(
           right_wing1 == 1 ~ left_affect,
           right_wing1 == 0 ~ right_affect
         ),
         polar_voters = case_when(
           right_wing == 1 ~ right_affect - left_affect,
           right_wing == 0 ~ left_affect - right_affect
         ),
         polar_voters1 = case_when(
           right_wing1 == 1 ~ right_affect - left_affect,
           right_wing1 == 0 ~ left_affect - right_affect
         ),
         edu = case_when(
           educ < 3 ~ "Less then HS",
           educ %in% 4:5 ~ "HS",
           educ %in% 5:8 ~ "Academic"
         ),
         relig = case_when(
           v144 == 1 ~ "V. Relig",
           v144 == 2 ~ "Relig",
           v144 %in% 3:4 ~ "Traditional",
           v144  == 5 ~ "Secular"),
         ashkenazi = ifelse(v135 == 1, 1, 0),
         spending = case_when(
           v139 < 6 ~ v139 ),# 1.alot over average, 2. a bit 3. average 4. above 5. a lot above 
         knowledge = ifelse(v73==1,1,0),
         turnout = NA,
         politc_conv = NA,
         Sex = ifelse(gender == 1, "male", "female"))


#Select relevant variables for analysis
ines_2019 <- ines_2019 %>% 
  select(.,c(date, age, midgam, days_before_elec:Sex)) %>% 
  rename(.,
         week = midgam)



# ----------------------------------------------------------------------
# Clean INES 2015
# ----------------------------------------------------------------------

### Read data

ines_2015 <- read.dta13("Raw Data/INES/2015/2015.dta")

### Create treatment -- Time before/after election

# Create election date vector and convert date vector to date format

ines_2015 <- ines_2015 %>% 
  mutate(.,
         election_day = "17/03/2015",
         date = as.Date(date, format = "%d/%m/%Y"),
         election_day = as.Date(election_day, "%d/%m/%Y"))   

# create days before election indicator

ines_2015<- ines_2015 %>% 
  mutate(.,
         days_before_elec = as.numeric(difftime(election_day ,date , units = c("days"))))

# create indicator of self reported partisanship

ines_2015 <- ines_2015 %>% 
  mutate(.,
         right_wing = case_when(
           v103 %in% 1:3 ~ 1,
           v103 %in% 5:7 ~ 0),
         right_wing1 = case_when(
           v103 %in% 1:2 ~ 1,
           v103 %in% 6:7 ~ 0),
         center = ifelse(v103 == 4, 1, 0),
         right = case_when(
           v103 %in% 1:3 ~ 1,
           v103 %in% 4:7 ~ 0),
         left = case_when(
           v103 %in% 1:4 ~ 0,
           v103 %in% 5:7 ~ 1),
         election_year = 2015
  )


# Filter sample to include only Jews
ines_2015 <- ines_2015 %>% 
  filter(.,
         v148 == 1)


## Create polarization variables
# Left wing parties: Labor (B51), Meretz (G51)
# Right wing: Likud (A51), Jewish Home (C51), Israel Betenu (H51)
# Left wing leaders: Buji (B56)
# Right wing leaders: Bibi (A56)

#Recode 99 as NA
ines_2015<- ines_2015 %>% 
  replace_with_na(replace = list(v51A = 99,
                                 v51B = 99,
                                 v51C = 99,
                                 v51G = 99,
                                 v51H = 99,
                                 v51I = 99,
                                 v56A = 99,
                                 v56B = 99))

#Create outcomes and covariates
ines_2015 <- ines_2015 %>% rowwise() %>%  
  mutate(.,
         left_party_affect = mean(c(v51B,v51G), na.rm = T),
         right_party_affect = mean(c(v51A,v51C,v51H), na.rm = T),
         arab_party_affect = v51J,
         uo_party_affect = v51E,
         ext_right_party_affect = v51C,
         party_affect = case_when(
           right_wing == 1 ~ left_party_affect,
           right_wing == 0 ~ right_party_affect
         ),
         in_party_affect = case_when(
           right_wing == 1 ~ right_party_affect,
           right_wing == 0 ~ left_party_affect
         ),
         party_affect1 = case_when(
           right_wing1 == 1 ~ left_party_affect,
           right_wing1 == 0 ~ right_party_affect
         ),
         party_polar = case_when(
           right_wing == 1 ~ right_party_affect - left_party_affect,
           right_wing == 0 ~ left_party_affect - right_party_affect
         ),
         main_party_polar = case_when(
           right_wing == 1 ~ v51A - v51B,
           right_wing == 0 ~ v51B - v51A
         ),
         extr_party_polar = case_when(
           right_wing == 1 ~ ext_right_party_affect - v51G,
           right_wing == 0 ~ v51G - ext_right_party_affect
         ),
         party_polar1 = case_when(
           right_wing1 == 1 ~ right_party_affect - left_party_affect,
           right_wing1 == 0 ~ left_party_affect - right_party_affect
         ),
         leader_affect = case_when(
           right_wing == 1 ~ v56B,
           right_wing == 0 ~ v56A
         ),
         leader_affect1 = case_when(
           right_wing1 == 1 ~ v56B,
           right_wing1 == 0 ~ v56A
         ),
         leader_polar = case_when(
           right_wing == 1 ~ v56A - v56B,
           right_wing == 0 ~ v56B - v56A
         ),
         leader_polar1 = case_when(
           right_wing1 == 1 ~ v56A - v56B,
           right_wing1 == 0 ~ v56B - v56A
         ), 
         ashkenazi = ifelse(v120 == 1,1,0),
         edu = case_when(
           v128 < 3 ~ "Less then HS",
           v128 %in% 4:5 ~ "HS",
           v128 %in% 5:8 ~ "Academic"
         ),
         relig = case_when(
           v139 == 1 ~ "V. Relig",
           v139 == 2 ~ "Relig",
           v139 %in% 3:4 ~ "Traditional",
           v139  == 5 ~ "Secular"),
         spending = case_when(
           v134 <6 ~ v134),
         knowledge = ifelse(v86==1,1,0),
         turnout = case_when(
           v91 == 1 ~ 4,
           v91 == 2 ~ 3,
           v91 == 3 ~ 2,
           v91 == 4 ~ 1),
         politc_conv = case_when(
           v49 == 1 ~ 4,
           v49 == 2 ~ 3,
           v49 == 3 ~ 2,
           v49 == 4 ~ 1
         ),
         Sex = ifelse(sex == 1, "male", "female"))


#Select relevant variables for analysis
ines_2015 <- ines_2015 %>% 
  select(.,c(date, age, midgam, days_before_elec:Sex)) %>% 
  rename(.,
         week = midgam)

#Bind 2019 and 2015 datasets
ines_2019b <- ines_2019b <- ines_2019[, names(ines_2019) %in% names(ines_2015)]
ines_2015b <- ines_2015b <- ines_2015[, names(ines_2015) %in% names(ines_2019)]
ines_master <- rbind(ines_2019b, ines_2015b)



# ----------------------------------------------------------------------
# Clean INES 2013
# ----------------------------------------------------------------------

### Read data

ines_2013 <- read.dta13("Raw Data/INES/2013/2013.dta")

### Create treatment -- Time before/after election

# Create election date vector and convert date vector to date format

ines_2013 <- ines_2013 %>% 
  mutate(.,
         election_day = "22/01/2013",
         date = as.Date(date, format = "%d/%m/%Y"),
         election_day = as.Date(election_day, "%d/%m/%Y"))   

# create days before election indicator

ines_2013<- ines_2013 %>% 
  mutate(.,
         days_before_elec = as.numeric(difftime(election_day ,date , units = c("days"))))

# create indicator of self reported partisanship

ines_2013 <- ines_2013 %>% 
  mutate(.,
         v88 = case_when(
           v88 == "1. right-wing" ~ 1,
           v88 == 2 ~ 2,
           v88 == 3 ~ 3,
           v88 == 4 ~ 4,
           v88 == 5 ~ 5,
           v88 == 6 ~ 6,
           v88 == "7. left -wing" ~ 7),
         right_wing = case_when(
           v88 %in% 1:3 ~ 1,
           v88 %in% 5:7 ~ 0),
         right_wing1 = case_when(
           v88 %in% 1:2 ~ 1,
           v88 %in% 6:7 ~ 0),
         center = ifelse(v88 == 4, 1, 0),
         right = case_when(
           v88 %in% 1:3 ~ 1,
           v88 %in% 4:7 ~ 0),
         left = case_when(
           v88 %in% 1:4 ~ 0,
           v88 %in% 5:7 ~ 1),
         election_year = 2013
  )



# Filter sample to include only Jews
ines_2013 <- ines_2013 %>% 
  filter(.,
         v153 == "1. jewish")


## Create polarization variables

# Re-code affect measures as numeric
ines_2013 <- ines_2013 %>%
  mutate(.,
    v45A_. = case_when(
      v45A == "0. strong rejection  (hatred)" ~ 0,
      v45A == "10. strong attraction (affection)" ~ 10,
      v45A == 1 ~ 1,
      v45A == 2 ~ 2,
      v45A == 3 ~ 3,
      v45A == 4 ~ 4,
      v45A == 5 ~ 5,
      v45A == 6 ~ 6,
      v45A == 7 ~ 7,
      v45A == 8 ~ 8,
      v45A == 9 ~ 9),
    v45B_. = case_when(
      v45B == "0. strong rejection  (hatred)" ~ 0,
      v45B == "10. strong attraction (affection)" ~ 10,
      v45B == 1 ~ 1,
      v45B == 2 ~ 2,
      v45B == 3 ~ 3,
      v45B == 4 ~ 4,
      v45B == 5 ~ 5,
      v45B == 6 ~ 6,
      v45B == 7 ~ 7,
      v45B == 8 ~ 8,
      v45B == 9 ~ 9),
    v45C_. = case_when(
      v45C == "0. strong rejection  (hatred)" ~ 0,
      v45C == "10. strong attraction (affection)" ~ 10,
      v45C == 1 ~ 1,
      v45C == 2 ~ 2,
      v45C == 3 ~ 3,
      v45C == 4 ~ 4,
      v45C == 5 ~ 5,
      v45C == 6 ~ 6,
      v45C == 7 ~ 7,
      v45C == 8 ~ 8,
      v45C == 9 ~ 9),
    v45D_. = case_when(
      v45D == "0. strong rejection  (hatred)" ~ 0,
      v45D == "10. strong attraction (affection)" ~ 10,
      v45D == 1 ~ 1,
      v45D == 2 ~ 2,
      v45D == 3 ~ 3,
      v45D == 4 ~ 4,
      v45D == 5 ~ 5,
      v45D == 6 ~ 6,
      v45D == 7 ~ 7,
      v45D == 8 ~ 8,
      v45D == 9 ~ 9),
    v45E_. = case_when(
      v45E == "0. strong rejection  (hatred)" ~ 0,
      v45E == "10. strong attraction (affection)" ~ 10,
      v45E == 1 ~ 1,
      v45E == 2 ~ 2,
      v45E == 3 ~ 3,
      v45E == 4 ~ 4,
      v45E == 5 ~ 5,
      v45E == 6 ~ 6,
      v45E == 7 ~ 7,
      v45E == 8 ~ 8,
      v45E == 9 ~ 9),
    v45F_. = case_when(
      v45F == "0. strong rejection  (hatred)" ~ 0,
      v45F == "10. strong attraction (affection)" ~ 10,
      v45F == 1 ~ 1,
      v45F == 2 ~ 2,
      v45F == 3 ~ 3,
      v45F == 4 ~ 4,
      v45F == 5 ~ 5,
      v45F == 6 ~ 6,
      v45F == 7 ~ 7,
      v45F == 8 ~ 8,
      v45F == 9 ~ 9),
    v45G_. = case_when(
      v45G == "0. strong rejection  (hatred)" ~ 0,
      v45G == "10. strong attraction (affection)" ~ 10,
      v45G == 1 ~ 1,
      v45G == 2 ~ 2,
      v45G == 3 ~ 3,
      v45G == 4 ~ 4,
      v45G == 5 ~ 5,
      v45G == 6 ~ 6,
      v45G == 7 ~ 7,
      v45G == 8 ~ 8,
      v45G == 9 ~ 9),
    v46A_. = case_when(
      v46A == "0. strong rejection  (hatred)" ~ 0,
      v46A == "10. strong attraction (affection)" ~ 10,
      v46A == 1 ~ 1,
      v46A == 2 ~ 2,
      v46A == 3 ~ 3,
      v46A == 4 ~ 4,
      v46A == 5 ~ 5,
      v46A == 6 ~ 6,
      v46A == 7 ~ 7,
      v46A == 8 ~ 8,
      v46A == 9 ~ 9),
    v46B_. = case_when(
      v46B == "0. strong rejection  (hatred)" ~ 0,
      v46B == "10. strong attraction (affection)" ~ 10,
      v46B == 1 ~ 1,
      v46B == 2 ~ 2,
      v46B == 3 ~ 3,
      v46B == 4 ~ 4,
      v46B == 5 ~ 5,
      v46B == 6 ~ 6,
      v46B == 7 ~ 7,
      v46B == 8 ~ 8,
      v46B == 9 ~ 9),
    v46C_. = case_when(
      v46C == "0. strong rejection  (hatred)" ~ 0,
      v46C == "10. strong attraction (affection)" ~ 10,
      v46C == 1 ~ 1,
      v46C == 2 ~ 2,
      v46C == 3 ~ 3,
      v46C == 4 ~ 4,
      v46C == 5 ~ 5,
      v46C == 6 ~ 6,
      v46C == 7 ~ 7,
      v46C == 8 ~ 8,
      v46C == 9 ~ 9),
    v46D_. = case_when(
      v46D == "0. strong rejection  (hatred)" ~ 0,
      v46D == "10. strong attraction (affection)" ~ 10,
      v46D == 1 ~ 1,
      v46D == 2 ~ 2,
      v46D == 3 ~ 3,
      v46D == 4 ~ 4,
      v46D == 5 ~ 5,
      v46D == 6 ~ 6,
      v46D == 7 ~ 7,
      v46D == 8 ~ 8,
      v46D == 9 ~ 9),
    v46E_. = case_when(
      v46E == "0. strong rejection  (hatred)" ~ 0,
      v46E == "10. strong attraction (affection)" ~ 10,
      v46E == 1 ~ 1,
      v46E == 2 ~ 2,
      v46E == 3 ~ 3,
      v46E == 4 ~ 4,
      v46E == 5 ~ 5,
      v46E == 6 ~ 6,
      v46E == 7 ~ 7,
      v46E == 8 ~ 8,
      v46E == 9 ~ 9),
    v46F_. = case_when(
      v46F == "0. strong rejection  (hatred)" ~ 0,
      v46F == "10. strong attraction (affection)" ~ 10,
      v46F == 1 ~ 1,
      v46F == 2 ~ 2,
      v46F == 3 ~ 3,
      v46F == 4 ~ 4,
      v46F == 5 ~ 5,
      v46F == 6 ~ 6,
      v46F == 7 ~ 7,
      v46F == 8 ~ 8,
      v46F == 9 ~ 9),
    v46G_. = case_when(
      v46G == "0. strong rejection  (hatred)" ~ 0,
      v46G == "10. strong attraction (affection)" ~ 10,
      v46G == 1 ~ 1,
      v46G == 2 ~ 2,
      v46G == 3 ~ 3,
      v46G == 4 ~ 4,
      v46G == 5 ~ 5,
      v46G == 6 ~ 6,
      v46G == 7 ~ 7,
      v46G == 8 ~ 8,
      v46G == 9 ~ 9))

# Left wing parties: Labor (B45), Meretz (G45)
# Right wing: Likud Betenu (A45), Jewish Home (D45)
# Left wing leaders: Sheli Yehimovitz (B46)
# Right wing leaders: Bibi (A46)

#Re-code education as numeric
ines_2013$v137 <- as.numeric(ines_2013$v137)

#Re-code outcomes and covariates
ines_2013 <- ines_2013 %>% rowwise() %>%  
  mutate(.,
         left_party_affect = mean(c(v45B_., v45G_.), na.rm = T),
         right_party_affect = mean(c(v45A_., v45D_.) , na.rm = T),
         uo_party_affect = v45E_.,
         ext_right_party_affect = v45D_.,
         party_affect = case_when(
           right_wing == 1 ~ left_party_affect,
           right_wing == 0 ~ right_party_affect
         ),
         in_party_affect = case_when(
           right_wing == 1 ~ right_party_affect,
           right_wing == 0 ~ left_party_affect
         ),
         party_affect1 = case_when(
           right_wing1 == 1 ~ left_party_affect,
           right_wing1 == 0 ~ right_party_affect
         ),
         party_polar = case_when(
           right_wing == 1 ~ right_party_affect - left_party_affect,
           right_wing == 0 ~ left_party_affect - right_party_affect
         ),
         main_party_polar = case_when(
           right_wing == 1 ~ v45A_. - v45B_.,
           right_wing == 0 ~ v45B_. - v45A_.
         ),
         extr_party_polar = case_when(
           right_wing == 1 ~ v45D_. - v45G_.,
           right_wing == 0 ~ v45G_. - v45D_.
         ),
         party_polar1 = case_when(
           right_wing1 == 1 ~ right_party_affect - left_party_affect,
           right_wing1 == 0 ~ left_party_affect - right_party_affect
         ),
         leader_affect = case_when(
           right_wing == 1 ~ v46B_.,
           right_wing == 0 ~ v46A_.
         ),
         leader_affect1 = case_when(
           right_wing1 == 1 ~ v46B_.,
           right_wing1 == 0 ~ v46A_.
         ),
         leader_polar = case_when(
           right_wing == 1 ~ v46A_. - v46B_.,
           right_wing == 0 ~ v46B_. - v46A_.
         ),
         leader_polar1 = case_when(
           right_wing1 == 1 ~ v46A_. - v46B_.,
           right_wing1 == 0 ~ v46B_. - v46A_.
         ), 
         ashkenazi = ifelse(grepl("europe", v133), 1, 0),
         edu = case_when(
           v137 < 3 ~ "Less then HS",
           v137 %in% 4:5 ~ "HS",
           v137 %in% 5:8 ~ "Academic"
         ),
         relig = case_when(
           v150 == "4.  hareidi (for arabs: very religious)" ~ "V. Relig",
           v150 == "3.  religious" ~ "Relig",
           v150 == "2.  traditional" ~ "Traditional",
           v150  == "1.  secular" ~ "Secular"
         ),
         spending = NA,
         knowledge = ifelse(grepl("right", v123),1,0),
         turnout = case_when(
           v100 == "1.  certain i will vote" ~ 4,
           v100 == "2.  think i will vote" ~ 3,
           v100 == "3.  do not think that i will vote" ~ 2, 
           v100 == "4.  certain i will not vote" ~ 1
         ),
         politc_conv = case_when(
           v43 == "1.  to a great degree" ~ 4,
           v43 == "2.  to a certain degree" ~ 3,
           v43 == "3.  to a small degree" ~ 2,
           v43 == "4.  not at all" ~ 1
         ),
         Sex = ifelse(sex == "1.  male", "male", "female"))

#Select relevant variables for analysis
ines_2013 <- ines_2013 %>% 
  select(.,c(date, age, week, days_before_elec:Sex)) %>% 
  select(., -c(v45A_.:v46G_.)) 



### Combine 2013 with other datasets
ines_masterb <- ines_masterb <- ines_master[, names(ines_master) %in% names(ines_2013)]
ines_2013b <- ines_2013b <- ines_2013[, names(ines_2013) %in% names(ines_master)]

ines_master <- rbind(ines_2013b, ines_masterb)

# Note that in 2013 household spending is NA because a similar question did not appear in the survey

# ----------------------------------------------------------------------
# Clean INES 2009
# ----------------------------------------------------------------------

### Read data

ines_2009 <- read.dta13("Raw Data/INES/2009/2009.dta") 
ines_2009 <- ines_2009 %>% 
  mutate(.,
         year = 2009)

### Create treatment -- Time before/after election

# Create election date vector and convert date vector to date format
ines_2009$date <- as.Date(with(ines_2009, paste(day, month, year, sep="-")), "%d-%m-%Y")


ines_2009 <- ines_2009 %>% 
  mutate(.,
         election_day = "10/02/2009",
         date = as.Date(date, format = "%d/%m/%Y"),
         election_day = as.Date(election_day, "%d/%m/%Y"))   

# create days before election indicator

ines_2009<- ines_2009 %>% 
  mutate(.,
         days_before_elec = as.numeric(difftime(election_day ,date , units = c("days"))))

# create indicator of self reported partisanship
`%notin%` <- Negate(`%in%`)
ines_2009 <- ines_2009 %>% 
  mutate(.,
         v135 = case_when(
           v135 == "1 right" ~ 1,
           v135 == 2 ~ 2,
           v135 == 3 ~ 3,
           v135 == 4 ~ 4,
           v135 == 5 ~ 5,
           v135 == 6 ~ 6,
           v135 == "7 left" ~ 7),
         v134 = case_when(
           v134 == "5. right" ~ 1,
           v134 == "4. moderate right" ~ 2,
           v134 == "3. center" ~ 3,
           v134 == "2. moderate left" ~ 4,
           v134 == "1. left" ~ 5),
         v90 = case_when(
           v90 == "10 right" ~ 0,
           v90 == 9 ~ 1,
           v90 == 8 ~ 2,
           v90 == 7 ~ 3,
           v90 == 6 ~ 4,
           v90 == 5 ~ 5,
           v90 == 4 ~ 6,
           v90 == 3 ~ 7,
           v90 == 2 ~ 8,
           v90 == 1 ~ 9,
           v90 == "0 left" ~ 10),
         right_wing = case_when(
           v135 %in% 1:3 ~ 1,
           v135 %in% 5:7 ~ 0,
           v134 %in% 1:2 ~ 1,
           v134 %in% 4:5 ~0, 
           v90 %in% 1:5 ~1,
           v90 %in% 6:10 ~0),
         right_wing1 = case_when(
           v135 %in% 1:2 ~ 1,
           v135 %in% 6:7 ~ 0,
           v134 == 1 ~ 1,
           v134 == 5 ~0, 
           v90 %in% 1:2 ~1,
           v90 %in% 9:10 ~0),
         center = case_when(
           v90 == 5 ~ 1,
           v135 == 4 ~ 1,
           v134 == 3 ~ 1
         ),
         left = case_when(
           v135 %in% 1:4 ~ 0,
           v135 %in% 5:7 ~ 1,
           v134 %in% 1:3 ~ 0,
           v134 %in% 4:5 ~1, 
           v90 %in% 1:5 ~0,
           v90 %in% 6:10 ~1),
         right = case_when(
           v135 %in% 1:3 ~ 1,
           v135 %in% 4:7 ~ 0,
           v134 %in% 1:2 ~ 1,
           v134 %in% 3:5 ~0, 
           v90 %in% 1:4 ~1,
           v90 %in% 5:10 ~0),
         election_year = 2009
  )

#Ensure that center dummy takes 0 for respondents who are not centrists
ines_2009$center[is.na(ines_2009$center)] <- 0

# Filter sample to include only jews
ines_2009 <- ines_2009 %>% 
  filter(.,
         v195 == "1. jewish")


## Create polarization variables

# Recode affect measures as numeric
ines_2009 <-  ines_2009 %>%
  mutate_at(.vars = vars(v61, v62, v63, v64, v65, v66, v67,
                         v69, v70, v71),
            .funs = funs(. = case_when(
              . == "1. rejection/hate" ~ 1,
              . == "10 support/sympathy" ~ 10,
              . == 2 ~ 2,
              . == 3 ~ 3,
              . == 4 ~ 4,
              . == 5 ~ 5,
              . == 6 ~ 6,
              . == 7 ~ 7,
              . == 8 ~ 8,
              . == 9 ~ 9)))

# Left wing parties: Labor (v62), Meretz (v64)
# Right wing: Likud (v63), Jewish Home (v65), Yisreal Betenu (v66)
# Left wing leaders: Barak (v70)
# Right wing leaders: Bibi (v71)

#Re-code education variable as numeric
ines_2009$v191 <- as.numeric(ines_2009$v191)

ines_2009 <- ines_2009 %>% rowwise() %>%  
  mutate(.,
         age = age_1,
         left_party_affect = mean(c(v62_., v64_.), na.rm = T),
         right_party_affect = mean(c(v63_., v65_., v66_.) , na.rm = T),
         uo_party_affect = v67_.,
         ext_right_party_affect = mean(c(v65_.) , na.rm = T),
         party_affect = case_when(
           right_wing == 1 ~ left_party_affect,
           right_wing == 0 ~ right_party_affect
         ),
         in_party_affect = case_when(
           right_wing == 1 ~ right_party_affect,
           right_wing == 0 ~ left_party_affect
         ),
         party_affect1 = case_when(
           right_wing1 == 1 ~ left_party_affect,
           right_wing1 == 0 ~ right_party_affect
         ),
         party_polar = case_when(
           right_wing == 1 ~ right_party_affect - left_party_affect,
           right_wing == 0 ~ left_party_affect - right_party_affect
         ),
         main_party_polar = case_when(
           right_wing == 1 ~ v63_. - v62_.,
           right_wing == 0 ~ v62_. - v63_.
         ),
         extr_party_polar = case_when(
           right_wing == 1 ~ v65_. - v64_.,
           right_wing == 0 ~ v64_. - v65_.
         ),
         party_polar1 = case_when(
           right_wing1 == 1 ~ right_party_affect - left_party_affect,
           right_wing1 == 0 ~ left_party_affect - right_party_affect
         ),
         leader_affect = case_when(
           right_wing == 1 ~ v70_.,
           right_wing == 0 ~ v71_.
         ),
         leader_affect1 = case_when(
           right_wing1 == 1 ~ v70_.,
           right_wing1 == 0 ~ v71_.
         ),
         leader_polar = case_when(
           right_wing == 1 ~ v71_. - v70_.,
           right_wing == 0 ~ v70_. - v71_.
         ),
         leader_polar1 = case_when(
           right_wing1 == 1 ~ v71_. - v70_.,
           right_wing1 == 0 ~ v70_. - v71_.
         ), 
         ashkenazi = ifelse(grepl("europe", v179a), 1, 0),
         edu = case_when(
           v191 < 3 ~ "Less then HS",
           v191 == 3 ~ "HS",
           v191 %in% 4:6 ~ "Academic"
         ),
         relig = case_when(
           v190 == "4. haredi" ~ "V. Relig",
           v190 == "3. religious" ~ "Relig",
           v190 == "2. traditional" ~ "Traditional",
           v190  == "1. secular" ~ "Secular"
         ),
         spending = case_when(
           grepl("1", v184) ~ 5,
           grepl("2", v184) ~ 4,
           grepl("3", v184) ~ 3,
           grepl("4", v184) ~ 2,
           grepl("5", v184) ~ 1
         ),
         knowledge = ifelse(grepl("right", v172),1,0),
         turnout = case_when(
           v152 == "1. i am certain that i will vote" ~ 4,
           v152 == "2. i think i will vote" ~ 3, 
           v152 == "3. i don’t think i will vote" ~ 2,
           v152 == "4. i am certain that i will not vote" ~ 1),
         politc_conv = case_when(
           v55 == "1.  to a great extent" ~ 4,
           v55 == "2.  to a certain extent" ~ 3,
           v55 == "3.  to a small extent" ~ 2,
           v55 == "4.  not at all" ~ 1
         ),
         Sex = case_when(
           sex_1 == "1. male" ~ "male",
           sex_2 == "1. male" ~ "male",
           sex_1 == "2. female" ~ "female",
           sex_2 == "2. female" ~ "female"
         ))


# Create week (wave) variable
ines_2009$week <- as.numeric(ines_2009$sample)
ines_2009 <- ines_2009 %>% 
  select(.,c(date, age, week, days_before_elec:Sex)) %>% 
  select(., -c(v61_.:v71_.))


### Combine 2009 with other datasets

ines_masterb <- ines_masterb <- ines_master[, names(ines_master) %in% names(ines_2009)]
ines_2009b <- ines_2009b <- ines_2009[, names(ines_2009) %in% names(ines_master)]

ines_master <- rbind(ines_2009b, ines_masterb)



# ----------------------------------------------------------------------
# Clean INES 2006
# ----------------------------------------------------------------------

### Read data

ines_2006 <- read.dta13("Raw Data/INES/2006/2006.dta") 
ines_2006 <- ines_2006 %>% 
  mutate(.,
         year = 2006)

### Create treatment -- Time before/after election

# Create election date vector and convert date vector to date format
ines_2006$date <- as.Date(with(ines_2006, 
                               paste(day, month, year, sep="-")), "%d-%m-%Y")


ines_2006 <- ines_2006 %>% 
  mutate(.,
         election_day = "28/03/2006",
         date = as.Date(date, format = "%d/%m/%Y"),
         election_day = as.Date(election_day, "%d/%m/%Y"))   

# create days before election indicator

ines_2006 <- ines_2006 %>% 
  mutate(.,
         days_before_elec = as.numeric(difftime(election_day ,date , units = c("days"))))


# create indicator of self reported partisanship
# Note in this wave it is a left right scale where right is higher values

ines_2006 <- ines_2006 %>% 
  mutate(.,
         right_wing = case_when(
           b7 > 5 ~ 1,
           b7 <5 ~ 0),
         right_wing1 = case_when(
           b7 > 8 ~ 1,
           b7 < 3 ~ 0),
         center = ifelse(
           b7 == 5, 1, 0),
         right = case_when(
           b7 > 5 ~ 1,
           b7 <6 ~ 0),
         left = case_when(
           b7 > 4 ~ 0,
           b7 <5 ~ 1),
         election_year = 2006)



# Filter sample to include only Jews
ines_2006 <- ines_2006 %>% 
  filter(.,
         d33 == "jewish")


## Create polarization variables

# Re-code affect measures as numeric
ines_2006 <-  ines_2006 %>%
  mutate_at(.vars = vars(a60, a62,
                         a61, a63, a64, a65),
            .funs = funs(. = case_when(
              . == 1 ~ 1,
              . == 10 ~ 10,
              . == 2 ~ 2,
              . == 3 ~ 3,
              . == 4 ~ 4,
              . == 5 ~ 5,
              . == 6 ~ 6,
              . == 7 ~ 7,
              . == 8 ~ 8,
              . == 9 ~ 9)))


# Left wing parties: Labor (a60), Meretz (a62)
# Right wing: Likud (a61), Jewish Home (a63), Yisreal Betenu (a64)
# Left wing leaders: Barak (a69)
# Right wing leaders: Bibi (a70)

ines_2006 <- ines_2006 %>% rowwise() %>%  
  mutate(.,
         age = d31,
         left_party_affect = mean(c(a60_., a62_.), na.rm = T),
         right_party_affect = mean(c(a61_., a63_., a64_.) , na.rm = T),
         uo_party_affect = a65_.,
         ext_right_party_affect = mean(c(a63_.) , na.rm = T),
         party_affect = case_when(
           right_wing == 1 ~ left_party_affect,
           right_wing == 0 ~ right_party_affect
         ),
         in_party_affect = case_when(
           right_wing == 1 ~ right_party_affect,
           right_wing == 0 ~ left_party_affect
         ),
         party_affect1 = case_when(
           right_wing1 == 1 ~ left_party_affect,
           right_wing1 == 0 ~ right_party_affect
         ),
         party_polar = case_when(
           right_wing == 1 ~ right_party_affect - left_party_affect,
           right_wing == 0 ~ left_party_affect - right_party_affect
         ),
         main_party_polar = case_when(
           right_wing == 1 ~ a61 - a60,
           right_wing == 0 ~ a60 - a61
         ),
         extr_party_polar = case_when(
           right_wing == 1 ~ a63 - a62,
           right_wing == 0 ~ a62 - a63
         ),
         party_polar1 = case_when(
           right_wing1 == 1 ~ right_party_affect - left_party_affect,
           right_wing1 == 0 ~ left_party_affect - right_party_affect
         ),
         leader_affect = case_when(
           right_wing == 1 ~ a69,
           right_wing == 0 ~ a70
         ),
         leader_affect1 = case_when(
           right_wing1 == 1 ~ a69,
           right_wing1 == 0 ~ a70
         ),
         leader_polar = case_when(
           right_wing == 1 ~ a70 - a69,
           right_wing == 0 ~ a69 - a70
         ),
         leader_polar1 = case_when(
           right_wing1 == 1 ~ a70 - a69,
           right_wing1 == 0 ~ a69 - a70
         ),
         edu = case_when(
           c75 < 12 ~ "Less then HS",
           c75 == 12  ~ "HS",
           c75 >12 ~ "Academic"
         ),
         relig = case_when(
           c88 == "haredi" ~ "V. Relig",
           c88 == "religious" ~ "Relig",
           c88 == "traditional" ~ "Traditional",
           c88  == "secular" ~ "Secular"
         ),
         ashkenazi = ifelse(grepl("europe", origin),1,0),
         spending = case_when(
           c80 == "much less" ~ 1,
           c80 == "a little less" ~ 2,
           c80 == "about the average" ~ 3,
           c80 == "a little more" ~ 4,
           c80 == "much more" ~ 5),
         knowledge = ifelse(c51 == "2%", 1, 0),
         turnout = NA,
         politc_conv = case_when(
           a53 == "a great amount" ~ 4,
           a53 == "a certain amount" ~ 3,
           a53 == "a small amount" ~ 2,
           a53 == "not at all" ~ 1),
         Sex = d36)



# Create week (wave) variable
ines_2006$week <- as.numeric(ines_2006$sevev)


### Combine 2006 with other datasets
ines_masterb <- ines_masterb <- ines_master[, names(ines_master) %in% names(ines_2006)]
ines_2006b <- ines_2006b <- ines_2006[, names(ines_2006) %in% names(ines_master)]

ines_master <- rbind(ines_2006b, ines_masterb)

# ----------------------------------------------------------------------
# Clean INES 2003
# ----------------------------------------------------------------------

### Read data

ines_2003 <- read.dta13("Raw Data/INES/2003/2003.dta") 
ines_2003 <- ines_2003 %>% 
  mutate(.,
         year = 2003,
         month = 01) %>% 
  rename(.,
         day = b96)


### Create treatment -- Time before/after election

# Create election date vector and convert date vector to date format
ines_2003$date <- as.Date(with(ines_2003, 
                               paste(day, month, year, sep="-")), "%d-%m-%Y")


ines_2003 <- ines_2003 %>% 
  mutate(.,
         election_day = "28/01/2003",
         date = as.Date(date, format = "%d/%m/%Y"),
         election_day = as.Date(election_day, "%d/%m/%Y"))   

# create days before election indicator

ines_2003 <- ines_2003 %>% 
  mutate(.,
         days_before_elec = as.numeric(difftime(election_day ,date , units = c("days"))))

# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_2003 <- ines_2003 %>% 
  mutate(.,
         right_wing = case_when(
           a49 < 4 ~ 1,
           a49 > 4 ~ 0),
         right_wing1 = case_when(
           a49 < 3 ~ 1,
           a49 > 5 ~ 0),
         center = ifelse(a49 == 4, 1, 0),
         right = case_when(
           a49 < 4 ~ 1,
           a49 > 3 ~ 0),
         left = case_when( 
           a49 < 5 ~ 0,
           a49 > 4 ~ 1),
         election_year = 2003)



# Filter sample to include only Jews
ines_2003 <- ines_2003 %>% 
  filter(.,
         jew == "jew")


## Create polarization variables



# Left wing parties: Labor (a27), Meretz (a29)
# Right wing: Likud (a28), Jewish Home (a30+a32), Yisreal Betenu (a34)
# Left wing leaders: Mitzna (a35)
# Right wing leaders: Sharon (a36)
ines_2003$age <- ines_2003$b74
ines_2003 <- ines_2003 %>% rowwise() %>%  
  mutate(.,
         left_party_affect = mean(c(a27, a29), na.rm = T),
         right_party_affect = mean(c(a28, a30, a32, a34) , na.rm = T),
         uo_party_affect = a33,
         arab_party_affect = a37,
         ext_right_party_affect = mean(c(a30, a32) , na.rm = T),
         party_affect = case_when(
           right_wing == 1 ~ left_party_affect,
           right_wing == 0 ~ right_party_affect
         ),
         in_party_affect = case_when(
           right_wing == 1 ~ right_party_affect,
           right_wing == 0 ~ left_party_affect
         ),
         party_affect1 = case_when(
           right_wing1 == 1 ~ left_party_affect,
           right_wing1 == 0 ~ right_party_affect
         ),
         party_polar = case_when(
           right_wing == 1 ~ right_party_affect - left_party_affect,
           right_wing == 0 ~ left_party_affect - right_party_affect
         ),
         main_party_polar = case_when(
           right_wing == 1 ~ a28 - a27,
           right_wing == 0 ~ a27 - a28
         ),
         extr_party_polar = case_when(
           right_wing == 1 ~ ext_right_party_affect - a29,
           right_wing == 0 ~ a29 - ext_right_party_affect
         ),
         party_polar1 = case_when(
           right_wing1 == 1 ~ right_party_affect - left_party_affect,
           right_wing1 == 0 ~ left_party_affect - right_party_affect
         ),
         leader_affect = case_when(
           right_wing == 1 ~ a35,
           right_wing == 0 ~ a36
         ),
         leader_affect1 = case_when(
           right_wing1 == 1 ~ a35,
           right_wing1 == 0 ~ a36
         ),
         leader_polar = case_when(
           right_wing == 1 ~ a36 - a35,
           right_wing == 0 ~ a35 - a36
         ),
         leader_polar1 = case_when(
           right_wing1 == 1 ~ a36 - a35,
           right_wing1 == 0 ~ a35 - a36
         ),
         edu = case_when(
           b82 < 12 ~ "Less then HS",
           b82 == 12 ~ "HS",
           b82 > 12  ~ "Academic"
         ),
         relig = case_when(
           b91 == "haredi" ~ "V. Relig",
           b91 == "religious" ~ "Relig",
           b91 == "traditional" ~ "Traditional",
           b91  == "secular" ~ "Secular"
         ),
         ashkenazi = case_when(
           b77 == 3 ~ 1,
           b77 == 4 ~ 1,
           b77 < 3 ~ 0,
           b77 == 4 ~ 1,
           b77 %in% 5:12 ~ 0,
           b77 %in% 13:14 ~ 1,
           b77 > 14 ~ 0
         ),
         spending = case_when(
           b85 == "much below average" ~ 1,
           b85 == "below average" ~ 2,
           b85 == "average" ~ 3,
           b85 == "a little above average" ~ 4,
           b85 == "much more than average" ~ 5
         ),
         knowledge = NA,
         turnout = NA,
         politc_conv = case_when(
           a74 == "great extent" ~ 4,
           a74 == "certain extent" ~ 3,
           a74 == "not very much" ~ 2,
           a74 == "not at all" ~ 1),
         Sex = b92
  )

# Create week (wave) variable
ines_2003$week <- as.numeric(ines_2003$wave)
ines_2003 <- ines_2003 %>% 
  select(.,c(date, age, week, days_before_elec:Sex)) 


### Combine 2003 with other datasets
ines_masterb <- ines_masterb <- ines_master[, names(ines_master) %in% names(ines_2003)]
ines_2003b <- ines_2003b <- ines_2003[, names(ines_2003) %in% names(ines_master)]

ines_master <- rbind(ines_master, ines_2003b)



# ----------------------------------------------------------------------
# Clean INES 2001
# ----------------------------------------------------------------------

### Read data

ines_2001 <- read.dta13("Raw Data/INES/2001/2001.dta") 
ines_2001 <- ines_2001 %>% 
  mutate(.,
         year = 2001,
         month = ifelse(b51 == "january", 1, 2)) %>% 
  rename(.,
         day = b52)


### Create treatment -- Time before/after election

# Create election date vector and convert date vector to date format
ines_2001$date <- as.Date(with(ines_2001, 
                               paste(day, month, year, sep="-")), "%d-%m-%Y")


ines_2001 <- ines_2001 %>% 
  mutate(.,
         election_day = "06/02/2001",
         date = as.Date(date, format = "%d/%m/%Y"),
         election_day = as.Date(election_day, "%d/%m/%Y"))

# create days before election indicator

ines_2001 <- ines_2001 %>% 
  mutate(.,
         days_before_elec = as.numeric(difftime(election_day ,date , 
                                                units = c("days"))))%>% 
  filter(.,
         days_before_elec > 0) # Omit one observation where date is mistage

# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_2001 <- ines_2001 %>% 
  mutate(.,
         right_wing = case_when(
           a49 < 4 ~ 1,
           a49 > 4 ~ 0),
         right_wing1 = case_when(
           a49 < 3 ~ 1,
           a49 > 5 ~ 0),
         center = ifelse(a49==4,1,0),
         right = case_when(
           a49 < 4 ~ 1,
           a49 > 3 ~ 0),
         left = case_when(
           a49 < 5 ~ 0,
           a49 > 4 ~ 1),
         election_year = 2001)



# Filter sample to include only Jews
ines_2001 <- ines_2001 %>% 
  filter(.,
         b55 != "arabic")


## Create polarization variables

# Left wing parties: Labor (a45)
# Right wing: Likud (a47)
# Left wing leaders: Barak (a50)
# Right wing leaders: Sharon (a46)
ines_2001$age <- ines_2001$b24
ines_2001 <- ines_2001 %>% 
  mutate(.,
         left_party_affect = a45,
         right_party_affect = a47,
         uo_party_affect = NA,
         arab_party_affect = a54,
         extr_party_polar = NA,
         ext_right_party_affect = NA,
         party_affect = case_when(
           right_wing == 1 ~ left_party_affect,
           right_wing == 0 ~ right_party_affect
         ),
         in_party_affect = case_when(
           right_wing == 1 ~ right_party_affect,
           right_wing == 0 ~ left_party_affect
         ),
         party_affect1 = case_when(
           right_wing1 == 1 ~ left_party_affect,
           right_wing1 == 0 ~ right_party_affect
         ),
         party_polar = case_when(
           right_wing == 1 ~ right_party_affect - left_party_affect,
           right_wing == 0 ~ left_party_affect - right_party_affect
         ),
         main_party_polar = case_when(
           right_wing == 1 ~ right_party_affect - left_party_affect,
           right_wing == 0 ~ left_party_affect - right_party_affect
         ),
         party_polar1 = case_when(
           right_wing1 == 1 ~ right_party_affect - left_party_affect,
           right_wing1 == 0 ~ left_party_affect - right_party_affect
         ),
         leader_affect = case_when(
           right_wing == 1 ~ a50,
           right_wing == 0 ~ a46
         ),
         leader_affect1 = case_when(
           right_wing1 == 1 ~ a50,
           right_wing1 == 0 ~ a46
         ),
         leader_polar = case_when(
           right_wing == 1 ~ a46 - a50,
           right_wing == 0 ~ a50 - a46
         ),
         leader_polar1 = case_when(
           right_wing1 == 1 ~ a46 - a50,
           right_wing1 == 0 ~ a50 - a46
         ),
         edu = case_when(
           b38 < 12 ~ "Less then HS",
           b38 == 12 ~ "HS",
           b38 > 12 ~ "Academic"
         ),
         relig = case_when(
           b27 == "haredi" ~ "V. Relig",
           b27 == "religious" ~ "Relig",
           b27 == "traditional" ~ "Traditional",
           b27  == "secular" ~ "Secular"
         ),
         ashkenazi = ifelse(grepl("europe", b33), 1,0),
         spending = case_when(
           b41 == "much below" ~ 1,
           b41 == "somewhat below" ~ 2,
           b41 == "average" ~ 3,
           b41 == "somewhat above" ~ 4,
           b41 == "more than average" ~ 5),
         knowledge = NA,
         turnout = NA,
         politc_conv = case_when(
           a73 == "great extent" ~ 4,
           a73 == "some" ~ 3,
           a73 == "little" ~ 2,
           a73 == "not at all" ~ 1),
         Sex = b47)

# Create week (wave) variable
ines_2001$week <- NA
ines_2001 <- ines_2001 %>% 
  select(.,c(date, age, week, days_before_elec:Sex)) 

### Combine 2001 with all other waves
ines_masterb <- ines_masterb <- ines_master[, names(ines_master) %in% names(ines_2001)]
ines_2001b <- ines_2001b <- ines_2001[, names(ines_2001) %in% names(ines_master)]


ines_master <- rbind(ines_masterb, ines_2001b)

write_csv(ines_master, "Data for analysis/ines_master.csv")
